package Framework;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;


public class pnl_Ancestor extends JPanel implements ActionListener{
	static  String CLASS = "JPanel_Anc";
	
	protected ImageIcon backgroundImage;  
    protected pnl_Ancestor backPanel; 
    public	  String		backgroundImagePath;
    public pnl_Ancestor() {
 	   super(); 
 	   this.setLayout(null);
 	   
		}
    
     public void setBackgroundImage( String as_image)  
     {  
     	backgroundImage = nv_ImageLoader.loadImage(as_image);
     	backgroundImagePath = as_image;
     } 
    
     public void paintComponent( Graphics g )  
     {  
         if( backgroundImage == null ){
     		setBackgroundImage(ConfigOpts.IMAGE_BACKGROUND_STANDARD);
     	} 
         g.drawImage(backgroundImage.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
     }
     
     protected void finalize() throws Throwable
 	{

 		debugMessage.log("Object " + CLASS + " Destructed.", 11);
 	}

	
	public void actionPerformed(ActionEvent e) {
		// Stub so all children have it for Dialogue callbacks
		debugMessage.log(CLASS + " Has no ActionEvent, but something is calling it!", 90);
	}
	
	public void enterSubMenu(pnl_Ancestor newPanel){
		debugMessage.log(CLASS + " Is entering submenu " + newPanel.CLASS, 30);
		
		newPanel.backPanel = this;
		this.getRootPane().setContentPane(newPanel);
		newPanel.getRootPane().validate();
		
	}
	
	void goBack(){
		debugMessage.log(CLASS + " Is going back from submenu to" + this.backPanel.CLASS, 30);
		if (this.backPanel != null){
			this.getRootPane().setContentPane(this.backPanel);
			this.backPanel.getRootPane().validate();
			this.backPanel.getRootPane().repaint();
		}
		else {
			goHome();
		}
		
		
	}
	void goHome(){
		debugMessage.log(CLASS + " Is going to Home menu.", 30);
		this.getRootPane().setContentPane(ConfigOpts.win_MainWindow);
		this.backPanel.getRootPane().validate();
		this.backPanel.getRootPane().repaint();
	}
	
	public void reset(){
		debugMessage.log(CLASS + " Is being reset. but " + CLASS + ".reset() has not been overridden!", 90);
		
	}
 }  

